package com.okyai.kt.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.okyai.common.annotation.Log;
import com.okyai.common.enums.BusinessType;
import com.okyai.kt.domain.RecordDetail;
import com.okyai.kt.service.IRecordDetailService;
import com.okyai.common.core.controller.BaseController;
import com.okyai.common.core.domain.AjaxResult;
import com.okyai.common.utils.poi.ExcelUtil;
import com.okyai.common.core.page.TableDataInfo;

/**
 * 档案明细Controller
 * 
 * @author okyai
 * @date 2021-03-20
 */
@Controller
@RequestMapping("/kt/record/detail")
public class RecordDetailController extends BaseController
{
    private String prefix = "kt/record/detail";

    @Autowired
    private IRecordDetailService recordDetailService;

    @RequiresPermissions("kt:detail:view")
    @GetMapping()
    public String detail()
    {
        return prefix + "/detail";
    }

    /**
     * 查询档案明细列表
     */
    @RequiresPermissions("kt:detail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RecordDetail recordDetail)
    {
        startPage();
        List<RecordDetail> list = recordDetailService.selectRecordDetailList(recordDetail);
        return getDataTable(list);
    }

    /**
     * 导出档案明细列表
     */
    @RequiresPermissions("kt:detail:export")
    @Log(title = "档案明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RecordDetail recordDetail)
    {
        List<RecordDetail> list = recordDetailService.selectRecordDetailList(recordDetail);
        ExcelUtil<RecordDetail> util = new ExcelUtil<RecordDetail>(RecordDetail.class);
        return util.exportExcel(list, "detail");
    }

    /**
     * 新增档案明细
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存档案明细
     */
    @RequiresPermissions("kt:detail:add")
    @Log(title = "档案明细", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RecordDetail recordDetail)
    {
        return toAjax(recordDetailService.insertRecordDetail(recordDetail));
    }

    /**
     * 修改档案明细
     */
    @GetMapping("/edit/{明细ID}")
    public String edit(@PathVariable("明细ID") Long 明细ID, ModelMap mmap)
    {
        RecordDetail recordDetail = recordDetailService.selectRecordDetailById(明细ID);
        mmap.put("recordDetail", recordDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存档案明细
     */
    @RequiresPermissions("kt:detail:edit")
    @Log(title = "档案明细", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RecordDetail recordDetail)
    {
        return toAjax(recordDetailService.updateRecordDetail(recordDetail));
    }

    /**
     * 删除档案明细
     */
    @RequiresPermissions("kt:detail:remove")
    @Log(title = "档案明细", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(recordDetailService.deleteRecordDetailByIds(ids));
    }
}
